<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="主办方" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="organizer">
              <a-input v-model="model.organizer" placeholder="请输入主办方"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="副标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subname">
              <a-input v-model="model.subname" placeholder="请输入副标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="SEO关键字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seoKeywords">
              <a-textarea v-model="model.seoKeywords" rows="4" placeholder="请输入SEO关键字" />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="SEO描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seoDescription">
              <a-textarea v-model="model.seoDescription" rows="4" placeholder="SEO描述" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tagId">
              <j-multi-select-tag
                type="list_multi"
                v-model="model.tagId"
                dictCode="ht_industry_tag,name,id"
                placeholder="请选择分类ID"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sort">
              <a-input-number v-model="model.sort" placeholder="请输入排序" style="width: 100%" />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content">
              <j-editor v-model="model.content" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="封面" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cover">
              <j-image-upload isMultiple v-model="model.cover"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime">
              <j-date placeholder="请选择开始时间" v-model="model.startTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime">
              <j-date placeholder="请选择结束时间" v-model="model.endTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="省ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="provinceId">
              <j-dict-select-tag type="list" v-model="model.provinceId" dictCode="" placeholder="请选择省ID" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityId">
              <j-dict-select-tag type="list" v-model="model.cityId" dictCode="" placeholder="请选择市ID" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="区ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="districtId">
              <j-dict-select-tag type="list" v-model="model.districtId" dictCode="" placeholder="请选择区ID" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="街道地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="streetAddress">
              <a-textarea v-model="model.streetAddress" rows="4" placeholder="请输入街道地址" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="楼/门牌号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="suiteAddress">
              <a-input v-model="model.suiteAddress" placeholder="请输入楼/门牌号"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <address-cascader ref="addressCascader" />
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="报名费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyCost">
              <a-input-number v-model="model.applyCost" placeholder="请输入报名费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditUsername">
              <a-input v-model="model.auditUsername" placeholder="请输入审批人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="审核状态：0-未审核 1-审核中 2-已通过 3-已驳回"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="auditStatus"
            >
              <j-dict-select-tag
                type="list"
                v-model="model.auditStatus"
                dictCode="audit_status"
                placeholder="请选择审核状态：0-未审核 1-审核中 2-已通过 3-已驳回"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditComments">
              <a-textarea v-model="model.auditComments" rows="4" placeholder="请输入审批意见" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="首页推荐" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isHomeRecommended">
              <j-dict-select-tag
                type="list"
                v-model="model.isHomeRecommended"
                dictCode="is_home_recommended"
                placeholder="请选择首页推荐"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import AddressCascader from '@/components/htxincailiao/address/AddressCascader.vue'

export default {
  name: 'HTIndustryExhibitionForm',
  components: {
    AddressCascader
  },
  props: {
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
        // 18 - 湖南
        // 275 - 长沙
        // 2916 - 岳麓区
        provinceId: '18',
        cityId: '275',
        districtId: '2916',
        auditStatus: 0,
        isHomeRecommended: 0
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        organizer: [{ required: true, message: '请输入主办方!' }],
        name: [{ required: true, message: '请输入标题!' }],
        content: [{ required: true, message: '请输入内容!' }],
        // cover: [{ required: true, message: '请输入封面!' }],
        startTime: [{ required: true, message: '请输入开始时间!' }],
        // endTime: [{ required: true, message: '请输入结束时间!' }],
        // provinceId: [
        //    { required: true, message: '请输入省ID!'},
        // ],
        // cityId: [
        //    { required: true, message: '请输入市ID!'},
        // ],
        // districtId: [
        //    { required: true, message: '请输入区ID!'},
        // ],
        // streetAddress: [
        //    { required: true, message: '请输入街道地址!'},
        // ],
        // applyCost: [
        //    { required: true, message: '请输入报名费!'},
        //    { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
        // ],
        auditStatus: [{ required: true, message: '请输入审核状态：0-未审核 1-审核中 2-已通过 3-已驳回!' }],
        isHomeRecommended: [{ required: true, message: '请输入首页推荐!' }]
      },
      url: {
        add: '/industry/hTIndustryExhibition/add',
        edit: '/industry/hTIndustryExhibition/edit',
        queryById: '/industry/hTIndustryExhibition/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.$refs.addressCascader.edit(record)
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      this.$refs.addressCascader.submitForm().then(model => {
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            let httpurl = ''
            let method = ''
            if (!this.model.id) {
              httpurl += this.url.add
              method = 'post'
            } else {
              httpurl += this.url.edit
              method = 'put'
            }
            const combieModel = {
              ...that.model,
              ...model
            }

            httpAction(httpurl, combieModel, method)
              .then(res => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.$emit('ok')
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.confirmLoading = false
              })
          }
        })
      })
    }
  }
}
</script>

